import {
  roleList,
  roleMenu,
  systemlogList,
  managerList,
  managerInfo,
  roleInfo,
  roleAdd,
  roleEdit,
  roleDelete,
  systemlogTypeList,
  managerEnabled,
  managerDelete,
  managerAdd,
  managerEdit
} from '@/api/system'
import utils from '@/utils/common'
var timeStamp = Number(new Date())
const system = {
  state: {},

  mutations: {},

  actions: {
    // 系统角色列表
    RoleList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        keyword: data.keyword,
        page: data.page,
        pageSize: data.pageSize
      }
      return new Promise((resolve, reject) => {
        roleList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统角色权限
    RoleMenu ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp
      }
      return new Promise((resolve, reject) => {
        roleMenu(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统角色获取
    RoleInfo ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id
      }
      return new Promise((resolve, reject) => {
        roleInfo(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统角色添加
    RoleAdd ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        name: data.name,
        remark: data.remark || '',
        menuIds: data.menuIds
      }
      return new Promise((resolve, reject) => {
        roleAdd(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统角色编辑
    RoleEdit ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id,
        name: data.name,
        remark: data.remark || '',
        menuIds: data.menuIds
      }
      return new Promise((resolve, reject) => {
        roleEdit(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统角色删除
    RoleDelete ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id
      }
      return new Promise((resolve, reject) => {
        roleDelete(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统操作日志列表
    SystemlogList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        keyword: data.keyword,
        logTypeId: data.logTypeId,
        startTime: data.startTime,
        endTime: data.endTime,
        page: data.page,
        pageSize: data.pageSize
      }
      return new Promise((resolve, reject) => {
        systemlogList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 系统操作日志类型列表
    SystemlogTypeList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp
      }
      return new Promise((resolve, reject) => {
        systemlogTypeList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 管理员列表
    ManagerList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        keyword: data.keyword,
        page: data.page,
        pageSize: data.pageSize
      }
      return new Promise((resolve, reject) => {
        managerList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 管理员详情
    ManagerInfo ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id
      }
      return new Promise((resolve, reject) => {
        managerInfo(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 管理员状态修改
    ManagerEnabled ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id,
        enabled: data.enabled
      }
      return new Promise((resolve, reject) => {
        managerEnabled(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 管理员添加
    ManagerAdd ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        loginName: data.loginName,
        password: data.password,
        roleId: data.roleId,
        userName: data.userName,
        enabled: data.enabled
      }
      return new Promise((resolve, reject) => {
        managerAdd(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 管理员编辑
    ManagerEdit ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id,
        roleId: data.roleId,
        userName: data.userName,
        enabled: data.enabled
      }
      return new Promise((resolve, reject) => {
        managerEdit(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 管理员删除
    ManagerDelete ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        id: data.id
      }
      return new Promise((resolve, reject) => {
        managerDelete(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default system
